//
//  RBPageListViewController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/12.
//

#import "RBPageListViewController.h"

@interface RBPageListViewController ()

@end

@implementation RBPageListViewController
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)prepareCatagoryView {
    _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.JXheightForHeaderInSection)];
    self.categoryView.titles = self.titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = RBColor(51, 51, 51);
    self.categoryView.titleColor = RBColor(153, 153, 153);
    self.categoryView.titleFont = RBPingFangFont(15);
    self.categoryView.titleSelectedFont = RBPingFangBlodFont(15);
    self.categoryView.titleLabelZoomEnabled = NO;
    self.categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
    UIView *bottomLineView = [[UIView alloc]init];
    bottomLineView.backgroundColor = RBColor(237, 237, 237);
    [self.categoryView addSubview:bottomLineView];
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    //是否隐藏底部线条
    bottomLineView.hidden = _isHidBottomLineView;
    _pagerView = [self preferredPagingView];
    self.pagerView.mainTableView.gestureDelegate = self;
    [self.view addSubview:self.pagerView];
    self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
}

- (JXPagerView *)preferredPagingView {
    JXPagerView *pagerView = [[JXPagerView alloc] initWithDelegate:self];
    return pagerView;
}
#pragma mark - JXPagerViewDelegate
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
    return self.userHeaderView;
}
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    return self.JXTableHeaderViewHeight;
}
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return self.JXheightForHeaderInSection;
}
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return self.categoryView;
}
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
    return self.categoryView.titles.count;
}
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
    RBListTabViewController *listTabVc = [[RBListTabViewController alloc] init];
    listTabVc.title = self.titles[index];
    listTabVc.isNeedHeader = self.isNeedHeader;
    listTabVc.isNeedFooter = self.isNeedFooter;
    if (index == 0) {
        listTabVc.dataListArray = @[@"测试数据0"].mutableCopy;
    }else if (index == 1) {
        listTabVc.dataListArray = @[@"测试数据1"].mutableCopy;
    }else {
        listTabVc.dataListArray = @[@"测试数据2"].mutableCopy;
    }
    return listTabVc;
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
        return NO;
    }
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.pagerView.frame = CGRectMake(0, self.topSpaceH, RBScreenWidth, self.view.height - self.bottomViewHeight-self.topSpaceH);
}
@end
